29#if defined(MRB_32BIT) && \
30 (defined(MRB_NAN_BOXING) || \
31 (defined(MRB_NO_BOXING) && \
32 (!defined(MRB_USE_FLOAT32) || defined(MRB_INT64)))) && \
33 !defined(MRB_ARY_NO_EMBED)
34# define MRB_ARY_NO_EMBED
37#ifdef MRB_ARY_NO_EMBED
38# define MRB_ARY_EMBED_LEN_MAX 0
40# define MRB_ARY_EMBED_LEN_MAX ((mrb_int)(sizeof(void*)*3/sizeof(mrb_value)))
55#ifndef MRB_ARY_NO_EMBED
61#define mrb_ary_ptr(v) ((struct RArray*)(mrb_ptr(v)))
62#define mrb_ary_value(p) mrb_obj_value((void*)(p))
63#define RARRAY(v) ((struct RArray*)(mrb_ptr(v)))
65#ifdef MRB_ARY_NO_EMBED
66#define ARY_EMBED_P(a) 0
67#define ARY_UNSET_EMBED_FLAG(a) (void)0
68#define ARY_EMBED_LEN(a) 0
69#define ARY_SET_EMBED_LEN(a,len) (void)0
70#define ARY_EMBED_PTR(a) ((mrb_value*)NULL)
72#define MRB_ARY_EMBED_MASK 7
73#define ARY_EMBED_P(a) ((a)->flags & MRB_ARY_EMBED_MASK)
74#define ARY_UNSET_EMBED_FLAG(a) ((a)->flags &= ~(MRB_ARY_EMBED_MASK))
75#define ARY_EMBED_LEN(a) ((mrb_int)(((a)->flags & MRB_ARY_EMBED_MASK) - 1))
76#define ARY_SET_EMBED_LEN(a,len) ((a)->flags = ((a)->flags&~MRB_ARY_EMBED_MASK) | ((uint32_t)(len) + 1))
77#define ARY_EMBED_PTR(a) ((a)->as.ary)
80#define ARY_LEN(a) (ARY_EMBED_P(a)?ARY_EMBED_LEN(a):(mrb_int)(a)->as.heap.len)
81#define ARY_PTR(a) (ARY_EMBED_P(a)?ARY_EMBED_PTR(a):(a)->as.heap.ptr)
82#define RARRAY_LEN(a) ARY_LEN(RARRAY(a))
83#define RARRAY_PTR(a) ARY_PTR(RARRAY(a))
84#define RARRAY_GETMEM(a, ptr, len) ARY_GETMEM(RARRAY(a), ptr, len)
85#define ARY_SET_LEN(a,n) do {\
86 if (ARY_EMBED_P(a)) {\
87 mrb_assert((n) <= MRB_ARY_EMBED_LEN_MAX); \
88 ARY_SET_EMBED_LEN(a,n);\
91 (a)->as.heap.len = (n);\
93#define ARY_CAPA(a) (ARY_EMBED_P(a)?MRB_ARY_EMBED_LEN_MAX:(a)->as.heap.aux.capa)
94#define MRB_ARY_SHARED 256
95#define ARY_SHARED_P(a) ((a)->flags & MRB_ARY_SHARED)
96#define ARY_SET_SHARED_FLAG(a) ((a)->flags |= MRB_ARY_SHARED)
97#define ARY_UNSET_SHARED_FLAG(a) ((a)->flags &= ~MRB_ARY_SHARED)
98#define ARY_GETMEM(a, ptr, len) do { \
99 struct RArray *MRB_UNIQNAME(_a_) = (a); \
100 if (ARY_EMBED_P(MRB_UNIQNAME(_a_))) { \
101 (len) = ARY_EMBED_LEN(MRB_UNIQNAME(_a_)); \
102 (ptr) = ARY_EMBED_PTR(MRB_UNIQNAME(_a_)); \
105 (len) = MRB_UNIQNAME(_a_)->as.heap.len; \
106 (ptr) = MRB_UNIQNAME(_a_)->as.heap.ptr; \
255#define mrb_ary_ref(mrb, ary, n) mrb_ary_entry(ary, n)
void mrb_ary_modify(mrb_state *, struct RArray *)
Prepares an array for modification.
Definition array.c:226
mrb_value mrb_ary_new(mrb_state *mrb)
Creates a new, empty array.
Definition array.c:92
mrb_value mrb_ary_clear(mrb_state *mrb, mrb_value self)
Removes all elements from an array, making it empty.
Definition array.c:1710
mrb_value mrb_ary_new_from_values(mrb_state *mrb, mrb_int size, const mrb_value *vals)
Creates a new array initialized with a given sequence of values.
Definition array.c:143
void mrb_ary_replace(mrb_state *mrb, mrb_value self, mrb_value other)
Replaces the contents of an array with the contents of another array.
Definition array.c:641
mrb_value mrb_ary_new_capa(mrb_state *, mrb_int)
Creates a new array with a specified initial capacity.
Definition array.c:76
mrb_value mrb_ary_shift(mrb_state *mrb, mrb_value self)
Removes and returns the first element from an array.
Definition array.c:886
void mrb_ary_concat(mrb_state *mrb, mrb_value self, mrb_value other)
Concatenates one array to another.
Definition array.c:525
mrb_value mrb_ary_splice(mrb_state *mrb, mrb_value self, mrb_int head, mrb_int len, mrb_value rpl)
Replaces a portion of an array with elements from another array or a single value.
Definition array.c:1160
void mrb_ary_push(mrb_state *mrb, mrb_value array, mrb_value value)
Pushes an element onto the end of an array.
Definition array.c:795
mrb_value mrb_assoc_new(mrb_state *mrb, mrb_value car, mrb_value cdr)
Creates a new array of size 2, typically used to represent an association (key-value pair).
Definition array.c:161
void mrb_ary_set(mrb_state *mrb, mrb_value ary, mrb_int n, mrb_value val)
Sets the element at a given index in an array.
Definition array.c:1099
mrb_value mrb_ary_splat(mrb_state *mrb, mrb_value value)
Creates a new array from a given value, performing a "splat" operation.
Definition array.c:1659
mrb_value mrb_ary_join(mrb_state *mrb, mrb_value ary, mrb_value sep)
Joins the elements of an array into a string, separated by a given separator.
Definition array.c:1847
mrb_value mrb_ary_pop(mrb_state *mrb, mrb_value ary)
Removes and returns the last element from an array.
Definition array.c:861
mrb_value mrb_ary_unshift(mrb_state *mrb, mrb_value self, mrb_value item)
Prepends an element to the beginning of an array.
Definition array.c:999
mrb_value mrb_ary_entry(mrb_value ary, mrb_int offset)
Retrieves an element from an array at a specific index.
Definition array.c:1765
mrb_value mrb_ary_resize(mrb_state *mrb, mrb_value ary, mrb_int new_len)
Resizes an array to a new length.
Definition array.c:372
mruby common platform definition"
#define MRB_END_DECL
End declarations in C mode.
Definition common.h:28
#define MRB_BEGIN_DECL
Start declarations in C mode.
Definition common.h:26
#define MRB_API
Declare a public mruby API function.
Definition common.h:108
#define mrb_static_assert(...)
The mrb_static_assert() macro function takes one or two arguments.
Definition mruby.h:108
Definition boxing_nan.h:40